#pragma once

#include "event_loop.h"
#include "net_callback.h"

namespace rr {
namespace nio {

class CTimer
{
public:
    using Sptr = std::shared_ptr<CTimer>;

    CTimer(EventLoop::Var loop);
    ~CTimer();

    void SetTimerCallback(const TimerCallback& cb) { cb_ = cb; }
    int32_t Start(int32_t timer_ms);
    void Close(const CloseCompleteCallback& cb);

private:
    static void OnTimer(uv_timer_t* handle);
    static void OnClose(uv_handle_t* handle);

    void HandleCloseComplete();

private:
    EventLoop::Var loop_;
    TimerCallback cb_;
    uv_timer_t uv_timer_{};
    CloseCompleteCallback close_cb_;
};


} //namespace 
} //namespace 